home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / src / WBBump_src.lha / WBBump_src / hmap2lut.asm < prev    next >
Encoding:
Assembly Source File  |  1999-06-30  |  4.3 KB  |  248 lines

  1. ****************
  2. * hmap2lut.asm *
  3. ****************
  4.  
  5.  
  6.  
  7. ***    WBBump - Bumpmapping on the Workbench!
  8.  
  9. ***    Copyright (C) 1999  Thomas Jensen - dm98411@edb.tietgen.dk
  10.  
  11. ***    This program is free software; you can redistribute it and/or modify
  12. ***    it under the terms of the GNU General Public License as published by
  13. ***    the Free Software Foundation; either version 2 of the License, or
  14. ***    (at your option) any later version.
  15.  
  16. ***    This program is distributed in the hope that it will be useful,
  17. ***    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ***    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ***    GNU General Public License for more details.
  20.  
  21. ***    You should have received a copy of the GNU General Public License
  22. ***    along with this program; if not, write to the Free Software Foundation,
  23. ***    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24.  
  25.  
  26.  
  27.  
  28.     MACHINE    68020
  29.  
  30.  
  31.     XDEF    hmap2lut_iiiiiiiiii
  32.  
  33.  
  34.  
  35. BOUNDS_UBYTE    MACRO        * \1 = reg
  36.  
  37.     cmp.w    #$ff,\1
  38.     bls    .j1\@
  39.     move.w    #$ff,\1
  40. .j1\@
  41.     ENDM
  42.  
  43.  
  44.  
  45.  
  46. GET_DIST    MACRO    * \1 = Dx    result reg (bits 0-15 will be cleared)
  47.             * \2 = Dx    temp reg (bits 8-15 must be 0)
  48.             * \3 = Dx    current pixel position
  49.             * \4 = Dx    current light position
  50.             * \5 = Ax    pointer to pixel 1 (eg. -1(a0))
  51.             * \6 = Ax    pointer to pixel 2 (eg. 1(a0))
  52.  
  53.     clr.w    \1
  54.     move.b    \6,\2        * pixel to the right
  55.     move.b    \5,\1        * pixel to the left
  56.     sub.w    \2,\1        * sub right pixel
  57.  
  58. *    asl.w    #2,\1        * make it look nicer
  59.  
  60.     add.w    \3,\1        * add current pixel position
  61.     sub.w    \4,\1        * sub light position
  62.  
  63.     * convert to positive value
  64.     bpl    .j1\@        * branch if plus
  65.     neg.w    \1        * else negate
  66. .j1\@
  67.  
  68.     ENDM
  69.  
  70.  
  71.  
  72.  
  73. ***    hmap2lut( source, blut[levels][256], levels, brighttable[256][256], hmap, lut, width, height, lightx, lighty )
  74.  
  75.  
  76. ***    Convert an 8bit heightmap to an 8 bit brightness map using a brightness table
  77. ***    of 256 x 256 entries and light x and y positions
  78.  
  79.  
  80. *** 40 source    :    ucharptr    - original buffer
  81. *** 36 blut    :    ucharptr    - brightness lookup table
  82. *** 32 levels    :    uchar        - levels in blut
  83. *** 28 brighttable:    ucharptr    - ptr to brightness table
  84. *** 24 hmap    :    ucharptr    - ptr to src heightmap
  85. *** 20 lut    :    ucharptr    - ptr to dest 8 bit 
  86. *** 16 width    :    uword
  87. *** 12 height    :    uword
  88. ***  8 lightx    :    sword
  89. ***  4 lighty    :    sword
  90.  
  91.  
  92. hmap2lut_iiiiiiiiii:
  93.     * store value af A4 (E requirement)
  94.     move.l    a4,a4store
  95.     move.l    a5,a5store
  96.     move.l    a6,a6store
  97.  
  98.     * get arguments from stack
  99.  
  100.     move.l    40(sp),.source
  101.     move.l    .source,a6
  102.  
  103.     move.l    36(sp),.blut
  104.     move.l    .blut,a5
  105.  
  106.     move.w    32+2(sp),.levels
  107.     move.w    .levels,d6
  108.  
  109.     move.l    28(sp),.brighttable
  110.     move.l    .brighttable,a2
  111.  
  112.     move.l    24(sp),.hmap
  113.     move.l    .hmap,a0
  114.  
  115.     move.l    20(sp),.lut
  116.     move.l    .lut,a1
  117.  
  118.     move.w    16+2(sp),.width
  119.     move.w    12+2(sp),.height
  120.  
  121.     move.w    8+2(sp),d0
  122.     move.w    .width,d1
  123.     lsr.w    #1,d1
  124.     sub.w    d1,d0
  125.     asr.w    #1,d0
  126.     add.w    d1,d0
  127.     move.w    d0,.lightx
  128.  
  129.     move.w    4+2(sp),d0
  130.     move.w    .height,d1
  131.     lsr.w    #1,d1
  132.     sub.w    d1,d0
  133.     asr.w    #1,d0
  134.     add.w    d1,d0
  135.     move.w    d0,.lighty
  136.  
  137.     move.l    .hmap,a3
  138.     sub.l    16(sp),a3
  139.  
  140.     move.l    .hmap,a4
  141.     add.l    16(sp),a4
  142.  
  143.  
  144.  
  145.     clr.l    d2    * we need to use (Ax,D2.l)
  146.  
  147.     clr.l    d5    * temp reg
  148.  
  149.  
  150.  
  151.     moveq.l    #0,d1    * d1 is y loop counter
  152. .ly
  153.     moveq.l    #0,d0    * d0 is x loop counter
  154. .lx
  155.  
  156.     * skip if at "ground"
  157.     cmp.b    #0,(a0)
  158.     beq    .drawthrough
  159.  
  160.     * light x
  161.  
  162.     GET_DIST    d2, d5, d0, .lightx, -1(a0), 1(a0)
  163.  
  164.  
  165.     * light y
  166.  
  167.     GET_DIST    d3, d5, d1, .lighty, (a3), (a4)
  168.  
  169.  
  170.  
  171.     * bounds check
  172.  
  173.     BOUNDS_UBYTE    d2    * convert values > 255 to 255
  174.  
  175.     BOUNDS_UBYTE    d3    * convert values > 255 to 255
  176.  
  177.  
  178.     * prepare index word
  179.  
  180.     lsl.w    #8,d2        * x in upper 8 bits of index word
  181.     move.b    d3,d2        * and y in the lower
  182.  
  183.  
  184.     * get the actual brightness and put it into buffer
  185.  
  186.     move.b    0(a2,d2.l),d7    * brightness in d7
  187.  
  188.     not.b    d7        * the brightness is actually darkness in the table (might change that)
  189.  
  190.     and.w    #$00ff,d7
  191.  
  192.     lsl.w    d6,d7
  193.  
  194.     move.b    (a6)+,d7
  195.  
  196.     move.b    0(a5,d7.w),(a1)+    * put it to buffer
  197.  
  198.  
  199.     bra    .nodrawthrough
  200. .drawthrough
  201.  
  202.     move.b    (a6)+,(a1)+
  203.  
  204. .nodrawthrough
  205.  
  206.  
  207.     * increase pointers
  208.     addq    #1,a0
  209.     addq    #1,a3
  210.     addq    #1,a4
  211.  
  212.  
  213.  
  214.     *** x loop ***
  215.     addq.w    #1,d0
  216.     cmp.w    .width,d0
  217.     bne    .lx
  218.  
  219.     *** y loop ***
  220.     addq.w    #1,d1
  221.     cmp.w    .height,d1
  222.     bne    .ly
  223.  
  224.     * put original a4 value back where it belongs
  225.     move.l    a4store,a4
  226.     move.l    a5store,a5
  227.     move.l    a6store,a6
  228.  
  229.     rts
  230.  
  231.  
  232. *** local variables
  233.  
  234. .source        dc.l    0
  235. .blut        dc.l    0
  236. .levels        dc.w    0
  237. .brighttable    dc.l    0
  238. .hmap        dc.l    0
  239. .lut        dc.l    0
  240. .width        dc.w    0
  241. .height        dc.w    0
  242. .lightx        dc.w    0
  243. .lighty        dc.w    0
  244.  
  245. a4store:    dc.l    0
  246. a5store:    dc.l    0
  247. a6store:    dc.l    0
  248.